<?php

namespace app\adminapi\export;

use app\services\product\product\StoreProductServices;

class StoreStockExport extends BaseExport
{
    protected $header = [
        '商品', '分类', '价格(元)', '上下架状态', '经销商', '可售库存', '销量'
    ];

    protected $mergeField = 'distributor_stock';

    public function createData(array $where)
    {
        $list = app()->make(StoreProductServices::class)->getStockList($where)['list'];
        
        $data = [];

        foreach ($list as $item) {
            foreach ($item['distributor_stock'] as $k1 => $item1) {
                $data[] = [
                    ($k1 == 0) ? $item['stock_name'] ?? '' : '',
                    ($k1 == 0) ? $item['cate_name'] ?? '' : '',
                    ($k1 == 0) ? $item['price'] ?? '' : '',
                    ($k1 == 0) ? ($item['is_show'] == 1 ? '上架' : '下架') : '',
                    $item1['distributor_name'] ?? '',
                    $item1['total_stock'] ?? 0,
                    $item1['has_sale_stock'] ?? 0
                ];
            }
        }
        return $data;
    }
}